<template>
	<view class="shippingaddress">
		<!-- <view class="header-top" :style="{height: top+'px'}">

		</view> -->
		<!-- <view class="header-line" >

			<view class="left" @click="shang">
				<u-icon name="arrow-left" size="20" color="#ffffff" />
			</view>
			<view class="right" style="text-align: center;">
				<view class="search">
					收货地址
				</view>
			</view>

		</view> -->
		<!-- <view class="box" :style="{height:'10'+'px'}">

		</view> -->
		<view class="shippingaddress_top">

		</view>
		<view class="shippingaddress_main">
			<view v-if="isshow" style="text-align: center;">
				<image src="../../static/iconShow/noOrder.png"></image>
			</view>
			<radio-group class="radio-group" >
				<label class="uni-list-cell uni-list-cell-pd"  v-for="(item, index) in listsss" :key="item.id">
					<view class="shippingaddress_main_a">
						<view @click="xuanzhong(item)" >
							<view class="shippingaddress_main_top" >
								<text class="text1">{{item.realName}}</text>
								<text class="text2">{{item.phone}}</text>
							</view>
							<view class="shippingaddress_main_zhong">
								<view>{{item.province}} {{item.city}} {{item.district}} {{item.detail}}</view>
								<view style="padding: 16rpx 0;"></view>
							</view>
						</view>
						
						<view class="shippingaddress_main_bottom">
							<view class="shippingaddress_main_bottom_left">
								<radio :value="String(item.isDefault)" color="#0EA970" @click="moren(item.id)" :checked="item.isDefault ==1"
									style="transform:scale(0.6)" />
								<!-- <view @click="xuanzhong(item)"> -->
								<view >
									<text v-if="item.isDefault==1">默认地址</text>
									<text v-if="item.isDefault==0">设为默认地址</text>
								</view>

							</view>
							<view class="shippingaddress_main_bottom_right">
								<text style="margin-right: 60rpx;" @click="redact(item.id)">编辑</text>
								<!-- <text @click="shippingdelete(item.id)">删除</text> -->
							</view>

						</view>
					</view>
				</label>
			</radio-group>
			<view class="shippingaddress_bottom_s" @click="site">
				新建地址
			</view>
		</view>

	</view>
</template>

<script>
	import homeServices from '../../service/homeService'
	export default {
		data() {
			return {
				checked: true,
				obj: true,
				ID: 1,
				// right: '',
				// padding: '',
				// top: '',
				// height: '',
				current: 0,
				lists: [],
				listss: [],
				listsss: [],
				selected: [],
				limit: 10,
				page: 1,
				ids: '',
				isshow:false
			}
		},
		methods: {
			async customeraddress() {
				let params = {
					limit: this.limit,
					page: this.page
				}
				let res = await homeServices.customeraddress(params)
				this.listsss = res.data
				if(this.listsss.length==0){
					this.isshow=true
				}else{
					this.isshow=false
				}

				console.log(this.listsss);
			},
			// 编辑
			redact(id) {
				uni.navigateTo({
					url: `/pagesB/redact/redact?id=${id}`
				})
			},


			// // 删除
			// async shippingdelete(id) {
			// 	this.ids = id
			// 	let params = {
			// 		id: this.ids
			// 	}
			// 	let res = await homeServices.shippingdelete(params)
			// 	console.log(res)
			// 	this.customeraddress()
			// },
			// 默认
			async moren(id) {
				this.ids = id

				let params = {
					id: id
				}
				let res = await homeServices.moren(params)
				console.log(res)
				this.listsss = []
				this.customeraddress()
			},
			// radioChange(evt) {
			// 	console.log("333333" + evt.detail.value)
			// 	for (let i = 0; i < this.listss.length; i++) {
			// 		if (this.listss[i].isDefault === evt.detail.value) {
			// 			this.current = i;
						
			// 			break;
			// 		}
			// 	}
				

			// },
			xuanzhong(item) {
				if (this.selected.indexOf(item) !== -1) {
					console.log(this.selected.indexOf(item));
					this.selected.splice(this.selected.indexOf(item), 1); //取消
				} else {
					this.selected.push(item); //选中添加到数组里

					this.lists = item
					// console.log(this.lists)
					uni.setStorageSync('addressId',item.id) 
					uni.redirectTo({
						url: `/pagesA/purchase/purchase?lists=` + JSON.stringify(this.lists)
					})
					
				}
			},
			site() {
				uni.navigateTo({
					url: '/pagesA/new/new'
				})
			},
			
		},
		onLoad() {
			// let meanInfo = uni.getMenuButtonBoundingClientRect()
			// let ScreenWidth = uni.getSystemInfoSync().screenWidth
			// let rpxTopx = ScreenWidth / 750
			// this.right = 30 * rpxTopx + meanInfo.width
			// this.padding = ScreenWidth - meanInfo.right
			// this.top = meanInfo.top
			// this.height = meanInfo.height
			this.listsss = []

		},
		onShow() {
			this.customeraddress()
		}
	}
</script>

<style lang="scss" scoped>
	@import '@/static/sass/shippingaddress.scss'
</style>
